<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';
require_once './include/advisory_db.php';
include("FCKeditor/fckeditor.php") ;
$status = $_SESSION['status'];

$smarty->compile_check = true;
include("./check/checkmycontact.php");

//Not A Recuiter
if($_SESSION[usertype] != "recruiter" ){
   echo "<meta http-equiv=\"refresh\" content=\"0;URL=errorall.php?errid=rc_1011\">";
   exit;	
}


$smarty->display('header.tpl');


//judge if current recruiter member has the group options
$groups = $DB->fetch_all("SELECT * FROM pa_contactgroup WHERE `cgp_rcid` = '".$_SESSION[uid]."'");
if(!empty($groups)){
	foreach($groups as $group){
		$groupOptions[$group['cgp_id']] = $group['cgp_title'];
	}
}

$postDate = date("m/d/Y",time());
//Edit
$editId = $_GET['editId'] + 0;
if($editId > 0 ){
	$contactData = $DB->fetch_one_array("SELECT * FROM pa_mycontacts WHERE `myc_id` = '".$editId."' AND `myc_rcid` = '".$_SESSION[uid]."'");
	if(empty($contactData)){
	   $err = "You are not authorized to view this page.";
	   $smarty->assign("err",$err);
	   $smarty->display('allleft.tpl');

	   $smarty->display("error.tpl");
	   $smarty->display("allright.tpl");
	   $smarty->display('footer.tpl');
	   exit;
	}
	if(empty($_POST)){
		$_POST = $contactData;
		$_POST[myc_gid] = explode(",",$contactData['myc_gid']);
	}
	$postDate = date("m/d/Y",$contactData['myc_created']);
	$actionUrl = "postcontact.php?editId=$editId";
}else{
	$gid = $_GET[gid]+0;
	if($gid>0) $_POST[myc_gid] = array($gid);
}

if($_GET['action'] == 'view'){
	$view = 1;
	$title   = "View Contacts";
}else{
	$title   = "Add/Edit Contacts";

}
if($_POST['myc_country'] == '0' || $_POST['myc_country'] == '')$_POST['myc_country'] = 211;
ob_clean();
ob_start();
$cpforms->formheader(array('title'=>'Contact Information','name'=>'article','action'=>$actionUrl));

$cpforms->makehidden(array('name'=>'action','value'=>'reg_contact'));
$cpforms->makehidden(array('name'=>'editId','value'=>"$editId"));
$cpforms->gethightext(array('text'=>"Add Date",'value'=>$postDate,'view'=>"1"));
if($editId >0){
$areFriends = (areFriends($contactData['myc_rcid'], $contactData['myc_fid']))?'Connected to You <a href="###" onmouseover="Tip(\'Connecting with someone on enetRecruiter allows you to easily send them messages and collaborate on job requisitions.\', WIDTH, 200,OFFSETY,20, SHADOW, true)"><img src="images/image003.png" width="16" border="0" align="absmiddle" /></a>':"Not Connected";
echo '<tr class="firstalt" nowrap><td width="40%" > Connection:</td>
	   <td width="60%" >
			<span style="font-weight:bold;color:#FF8C00">'.$areFriends.'</span>
		</td>
   </tr>';
}
$cpforms->gethightext(array('text'=>"First Name",'name'=>"myc_firstname",'only'=>1,'value'=>"$_POST[myc_firstname]",'view'=>"$view"));
$cpforms->gethightext(array('text'=>"Last Name",'name'=>"myc_lastname",'only'=>1,'value'=>"$_POST[myc_lastname]",'view'=>"$view"));
$cpforms->gethightext(array('text'=>"Email",'name'=>"myc_email",'only'=>1,'value'=>"$_POST[myc_email]",'view'=>"$view"));
$cpforms->gethightext(array('text'=>"Job Title",'name'=>"myc_jobtitle",'value'=>"$_POST[myc_jobtitle]",'view'=>"$view"));
$cpforms->gethightext(array('text'=>"Company",'name'=>"myc_company",'value'=>"$_POST[myc_company]",'view'=>"$view"));
$cpforms->gethightext(array('text'=>"Address 1",'name'=>"myc_address1",'value'=>"$_POST[myc_address1]",'view'=>"$view"));
$cpforms->gethightext(array('text'=>"Address 2",'name'=>"myc_address2",'value'=>"$_POST[myc_address2]",'view'=>"$view"));
$cpforms->gethightext(array('text'=>"City",'name'=>"myc_city",'value'=>"$_POST[myc_city]",'view'=>"$view"));
$cpforms->makeselect(array('one'=>1,'text'=>"State",'name'=>"myc_state",'selected'=>"$_POST[myc_state]",'view'=>"$view",'option'=> $state));
$cpforms->gethightext(array('text'=>"Zip Code",'name'=>"myc_zipcode",'value'=>"$_POST[myc_zipcode]",'view'=>"$view"));
$cpforms->makeselect(array('one'=>1,'text'=>"Country",'name'=>"myc_country",'selected'=>"$_POST[myc_country]",'view'=>"$view",'option'=> $country));
$cpforms->gethightext(array('text'=>"Mobile Phone",'name'=>"myc_mobilephone",'value'=>"$_POST[myc_mobilephone]",'view'=>"$view"));
$cpforms->gethightext(array('text'=>"Phone",'name'=>"myc_phone",'value'=>"$_POST[myc_phone]",'view'=>"$view"));
$cpforms->gethightext(array('text'=>"Fax",'name'=>"myc_fax",'value'=>"$_POST[myc_fax]",'view'=>"$view"));
$cpforms->gethightext(array('text'=>"Website",'name'=>"myc_website",'value'=>"$_POST[myc_website]",'view'=>"$view"));
$cpforms->makeselect(array('text'=>"Industry",'name'=>"myc_industry",'selected'=>"$_POST[myc_industry]",'view'=>"$view",'option'=> $jobcategory));
$cpforms->makeselect(array('text'=>"Specialty 1",'name'=>"myc_speciality1",'selected'=>"$_POST[myc_speciality1]",'view'=>"$view",'option'=> $jobfunction));
$cpforms->makeselect(array('text'=>"Specialty 2",'name'=>"myc_speciality2",'selected'=>"$_POST[myc_speciality2]",'view'=>"$view",'option'=> $jobfunction));
$cpforms->makeselect(array('text'=>"Specialty 3",'name'=>"myc_speciality3",'selected'=>"$_POST[myc_speciality3]",'view'=>"$view",'option'=> $jobfunction));

$cpforms->maketextarea(array('text'=>"Notes",'name'=>"myc_notes",'id'=>"myc_notes",'value'=>"$_POST[myc_notes]",'view'=>"$view"));
if($_SESSION['status'] == 'Premium'){
	if(empty($groupOptions)){
		$cpforms->gethightext(array('text'=>"Group Member",'value'=>"<a href=\"groups.php\">Create a group</a>",'view'=>"1"));
	}else{
		$cpforms->getBoxes(array('one'=>1,'text'=>"Group Member",'name'=>"myc_gid[]",'view'=>"$view",'selected'=>empty($_POST[myc_gid])?'':$_POST[myc_gid],'option'=>$groupOptions),"<br />");
	}
}
if($_GET['action'] == 'view'){
echo '<tr class="tbhead">
<td colspan="2" align="center" bgcolor="#F0F0F0">
 <input class="bginput button-secondary" type="button" value=" Edit "  onclick="location.href=\'postcontact.php?editId='.$editId.'\'"  /> 
 <input class="bginput button-secondary" type="button" name="" value=" Close "  onclick="window.close()"  /> 
<br></td></tr>
</table></td></tr>
</form></table>';
}else{
$cpforms->formfooter(array('confirm'=>1));
}

$reg_data = ob_get_contents();
ob_end_clean();
$content = "(<font color=red>*</font>=Required Field)";
$smarty->assign('title',$title);
$smarty->assign('content',$content);

if($err!=''){
$smarty->assign("err",$err);
}
$smarty->assign("reg",$reg_data);
$smarty->display('allleft.tpl');
$smarty->display('postcontact.tpl');

$smarty->display('allright.tpl');
$smarty->display('footer.tpl');
?>
